//
//  ViewController.m
//  Touch
//
//  Created by cocoazxj@163.com on 15/4/20.
//  Copyright (c) 2015年 handcool. All rights reserved.
//

#import "ViewController.h"
#import "DrawPad.h"

@interface ViewController ()<UIGestureRecognizerDelegate>
@property (nonatomic, strong) IBOutlet UIView *v_touch;
@property (nonatomic, strong) IBOutlet DrawPad *dp_view;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
//    [self gesture];
//    [self swipe];
//    [self press];
    [self makeCALayer];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)clearButtonClicked:(id)sender
{
    [self.dp_view clear];
}

- (IBAction)undoButtonClicked:(id)sender
{
    [self.dp_view undo];
}

- (IBAction)saveButtonClicked:(id)sender
{
    [self.dp_view save];
}

- (void)makeCALayer
{
    CALayer *layer = [CALayer layer];
    [layer setFrame:CGRectMake(20, 20, 60, 60)];
    [layer setBackgroundColor:[UIColor redColor].CGColor];
    layer.delegate = self;
    // 代理方法执行后 使用这个。
    [layer setNeedsDisplay];
    [self.view.layer addSublayer:layer];
}

- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx;
{
    CGContextAddEllipseInRect(ctx, CGRectMake(0, 0, 30, 30));
    CGContextSetRGBFillColor(ctx, 1, 0, 0, 1);
    CGContextStrokePath(ctx);
                              
}

- (void)gesture
{
    UITapGestureRecognizer *tgr = [[UITapGestureRecognizer alloc] init];
//    tgr.numberOfTouchesRequired = 2;
    [self.v_touch addGestureRecognizer:tgr];
    [tgr addTarget:self action:@selector(test)];
}

- (void)swipe
{
    UISwipeGestureRecognizer *wgr = [[UISwipeGestureRecognizer alloc] init];
    [self.v_touch addGestureRecognizer:wgr];
    [wgr addTarget:self action:@selector(test)];
}

- (void)press
{
    UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc] init];
    [self.v_touch addGestureRecognizer:lpgr];
    [lpgr addTarget:self action:@selector(test)];
}

- (void)test
{
    NSLog(@"-----------test");
}
@end
